```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring事务管理全解 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=NotoSans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .code-block {
            background: #1e293b;
            color: #f8fafc;
            border-left: 4px solid #7c3aed;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight {
            position: relative;
        }
        .highlight::after {
            content: '';
            position: absolute;
            left: 0;
            bottom: 2px;
            width: 100%;
            height: 8px;
            background-color: rgba(124, 58, 237, 0.3);
            z-index: -1;
            transition: all 0.2s ease;
        }
        .highlight:hover::after {
            height: 14px;
            background-color: rgba(124, 58, 237, 0.5);
        }
        .first-letter::first-letter {
            font-size: 3.5em;
            float: left;
            line-height: 0.8;
            margin-right: 0.1em;
            color: #4f46e5;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:py-32">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col items-center text-center">
                <div class="bg-white bg-opacity-10 rounded-full px-6 py-2 mb-6 inline-flex items-center">
                    <i class="fas fa-database mr-2"></i>
                    <span class="text-sm font-medium">Spring Framework</span>
                </div>
                <h1 class="text-4xl md:text-6xl font-bold mb-6 font-serif">Spring事务管理全解</h1>
                <p class="text-xl md:text-2xl max-w-3xl opacity-90 leading-relaxed">
                    探索Spring框架中三种核心事务管理方式的实现原理与最佳实践
                </p>
                <div class="mt-12 animate-bounce">
                    <i class="fas fa-chevron-down text-2xl opacity-70"></i>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-16">
        <!-- Introduction -->
        <section class="mb-20">
            <div class="first-letter text-lg md:text-xl leading-relaxed text-slate-700">
                Spring框架为Java应用程序提供了强大而灵活的事务管理能力。无论是简单的数据库操作还是复杂的分布式事务，Spring都能提供一致性的编程模型。本文将深入探讨Spring中三种主要的事务管理方式：编程式事务管理、XML配置的声明式事务管理以及注解驱动的事务管理，帮助开发者根据项目需求选择最适合的方案。
            </div>
        </section>

        <!-- Transaction Comparison Chart -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 text-center font-serif">事务管理方式对比</h2>
            <div class="mermaid">
                flowchart TD
                    A[Spring事务管理] --> B[编程式事务]
                    A --> C[声明式事务]
                    C --> D[XML配置]
                    C --> E[注解驱动]
                    B -->|优点| F[灵活控制]
                    B -->|缺点| G[代码侵入]
                    D -->|优点| H[集中管理]
                    D -->|缺点| I[配置复杂]
                    E -->|优点| J[简洁优雅]
                    E -->|缺点| K[分散关注]
            </div>
        </section>

        <!-- Programmatic Transaction -->
        <section class="mb-20">
            <div class="flex items-center mb-6">
                <div class="bg-indigo-100 text-indigo-800 rounded-full w-12 h-12 flex items-center justify-center mr-4">
                    <i class="fas fa-code text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">编程式事务管理</h2>
            </div>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <p class="text-lg leading-relaxed text-slate-700 mb-6">
                        通过编写代码来<span class="highlight font-medium">显式地管理</span>事务的开启、提交、回滚等操作。使用<code>TransactionTemplate</code>或者直接使用<code>PlatformTransactionManager</code>接口进行事务管理。
                    </p>
                    <div class="bg-indigo-50 p-6 rounded-lg border-l-4 border-indigo-500">
                        <h3 class="font-bold text-lg mb-3 text-indigo-800 flex items-center">
                            <i class="fas fa-lightbulb mr-2"></i>适用场景
                        </h3>
                        <ul class="space-y-2 text-slate-700">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mr-2 mt-1"></i>
                                <span>需要精细控制事务边界的情况</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mr-2 mt-1"></i>
                                <span>复杂的事务逻辑，需要条件性提交/回滚</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mr-2 mt-1"></i>
                                <span>遗留系统集成或特殊事务需求</span>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="code-block rounded-lg p-4 overflow-x-auto">
                    <pre><code class="text-sm language-java">// 获取事务管理器
PlatformTransactionManager transactionManager = ...;

// 创建TransactionDefinition，定义事务的属性
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

// 开启事务
TransactionStatus status = transactionManager.getTransaction(def);

try {
    // 执行数据库操作或其他业务逻辑
    // ...
    
    // 提交事务
    transactionManager.commit(status);
} catch (Exception e) {
    // 出现异常，回滚事务
    transactionManager.rollback(status);
}</code></pre>
                </div>
            </div>
        </section>

        <!-- XML Transaction -->
        <section class="mb-20">
            <div class="flex items-center mb-6">
                <div class="bg-purple-100 text-purple-800 rounded-full w-12 h-12 flex items-center justify-center mr-4">
                    <i class="fas fa-file-code text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">声明式事务管理（XML配置）</h2>
            </div>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <p class="text-lg leading-relaxed text-slate-700 mb-6">
                        通过在XML配置文件中声明事务切面（TransactionAspect），使用<code>&lt;tx:advice&gt;</code>来定义事务的传播行为、隔离级别、回滚规则等。
                    </p>
                    <div class="bg-purple-50 p-6 rounded-lg border-l-4 border-purple-500">
                        <h3 class="font-bold text-lg mb-3 text-purple-800 flex items-center">
                            <i class="fas fa-lightbulb mr-2"></i>适用场景
                        </h3>
                        <ul class="space-y-2 text-slate-700">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mr-2 mt-1"></i>
                                <span>需要集中管理事务配置的项目</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mr-2 mt-1"></i>
                                <span>不希望事务配置分散在代码各处</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mr-2 mt-1"></i>
                                <span>使用传统Spring XML配置的项目</span>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="code-block rounded-lg p-4 overflow-x-auto">
                    <pre><code class="text-sm language-xml">&lt;tx:advice id="txAdvice" transaction-manager="transactionManager"&gt;
    &lt;tx:attributes&gt;
        &lt;tx:method name="save*" propagation="REQUIRED" rollback-for="Exception" /&gt;
        &lt;tx:method name="*" propagation="REQUIRED" /&gt;
    &lt;/tx:attributes&gt;
&lt;/tx:advice&gt;

&lt;aop:config&gt;
    &lt;aop:advisor advice-ref="txAdvice" pointcut="execution(* com.example.*.*(..))" /&gt;
&lt;/aop:config&gt;</code></pre>
                </div>
            </div>
        </section>

        <!-- Annotation Transaction -->
        <section class="mb-20">
            <div class="flex items-center mb-6">
                <div class="bg-pink-100 text-pink-800 rounded-full w-12 h-12 flex items-center justify-center mr-4">
                    <i class="fas fa-tags text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">注解驱动的事务管理</h2>
            </div>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <p class="text-lg leading-relaxed text-slate-700 mb-6">
                        使用<code>@EnableTransactionManagement</code>注解来启用注解驱动的事务管理，然后在需要事务管理的方法上使用<code>@Transactional</code>注解。
                    </p>
                    <div class="bg-pink-50 p-6 rounded-lg border-l-4 border-pink-500">
                        <h3 class="font-bold text-lg mb-3 text-pink-800 flex items-center">
                            <i class="fas fa-lightbulb mr-2"></i>适用场景
                        </h3>
                        <ul class="space-y-2 text-slate-700">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-pink-500 mr-2 mt-1"></i>
                                <span>现代Spring Boot应用开发</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-pink-500 mr-2 mt-1"></i>
                                <span>希望事务配置与业务代码紧密结合</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-pink-500 mr-2 mt-1"></i>
                                <span>偏好注解式配置而非XML</span>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="code-block rounded-lg p-4 overflow-x-auto">
                    <pre><code class="text-sm language-java">@Configuration
@EnableTransactionManagement
public class AppConfig {
    // 配置数据源、实体管理器等相关Bean
}

@Service
public class MyService {
    
    @Autowired
    private MyRepository myRepository;
    
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void saveData(Data data) {
        // 执行数据库操作或其他业务逻辑
        myRepository.save(data);
    }
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Best Practices -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 text-center font-serif">事务管理最佳实践</h2>
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white p-6 rounded-xl shadow-md card-hover transition-all duration-300">
                    <div class="text-blue-500 mb-4">
                        <i class="fas fa-sitemap text-3xl"></i>
                    </div>
                    <h3 class="font-bold text-xl mb-3">传播行为选择</h3>
                    <p class="text-slate-600">
                        根据业务需求选择合适的传播行为，如REQUIRED、REQUIRES_NEW、NESTED等，避免不合理使用导致事务问题。
                    </p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-md card-hover transition-all duration-300">
                    <div class="text-green-500 mb-4">
                        <i class="fas fa-clock text-3xl"></i>
                    </div>
                    <h3 class="font-bold text-xl mb-3">事务超时设置</h3>
                    <p class="text-slate-600">
                        为长时间运行的事务设置合理的超时时间，防止事务长时间占用数据库连接导致系统性能下降。
                    </p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-md card-hover transition-all duration-300">
                    <div class="text-yellow-500 mb-4">
                        <i class="fas fa-exclamation-triangle text-3xl"></i>
                    </div>
                    <h3 class="font-bold text-xl mb-3">异常处理</h3>
                    <p class="text-slate-600">
                        明确指定需要回滚的异常类型，避免非受检异常导致事务意外提交或需要回滚的异常未被捕获。
                    </p>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto px-4 max-w-5xl">
            <div class="flex flex-col items-center">
                <div class="text-2xl font-bold mb-4 text-white">技术小馆</div>
                <a href="http://www.yuque.com/jtostring" class="text-gray-400 hover:text-white transition-colors duration-300">
                    <i class="fas fa-link mr-2"></i>http://www.yuque.com/jtostring
                </a>
                <div class="mt-6 flex space-x-4">
                    <a href="#" class="text-gray-400 hover:text-white transition-colors duration-300">
                        <i class="fab fa-github text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white transition-colors duration-300">
                        <i class="fab fa-twitter text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white transition-colors duration-300">
                        <i class="fab fa-weixin text-xl"></i>
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'dark',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            },
            fontFamily: 'Noto Sans SC, sans-serif'
        });
        
        // Smooth scroll for anchor links
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
        
        // Highlight code blocks
        document.querySelectorAll('pre code').forEach((block) => {
            hljs.highlightBlock(block);
        });
    </script>
</body>
</html>
```